package com.sc.web.gwt.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.sc.web.gwt.client.service.AdminDataManagementService;
import com.sc.web.gwt.server.persistence.AdminPersistence;
import com.sc.web.gwt.shared.model.Admin;

import java.util.List;

/**
 * com.sc.web.gwt.server.service
 * Author: AVAVT
 * Date: 8/10/11
 * Time: 1:22 AM
 */
public class AdminDataManagementServiceImpl extends RemoteServiceServlet implements AdminDataManagementService {
    AdminPersistence adminPersistence = new AdminPersistence();

    public List<Admin> getAllAdmins() {
        return adminPersistence.getAllAdmins();
    }

    public boolean saveOrUpdateAdminData(Admin agentAdmin) {
        if (agentAdmin.getAdminId() != -1)
            return adminPersistence.updateAdmin(agentAdmin);
        else {
            return adminPersistence.insertAdmin(agentAdmin);
        }
    }

    public Admin getAdminInfo() {
        Admin result = adminPersistence.getAdmin((Integer)getThreadLocalRequest().getSession().getAttribute("userId"));

        return result;
    }
}